#include<iostream>
#include<string.h>
#include<memory.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

typedef struct LNode
{
	int data;
	struct LNode *next;
}tLNode;

tLNode * head;

void addNode(int n);

void createList(int array[],int n)
{
	head = new tLNode();//head = (tLNode*)malloc(sizeof(tLNode));
	head->next = NULL;
	for(int i=0;i<n;i++)
	{
		addNode(array[i]);
	}
}

void 
addNode(int n)
{
	tLNode *p,*q;
	p = new tLNode();//p = (tLNode *)malloc(sizeof(tLNode));
	p->data = n;
	q = head;
	while(q->next != NULL )
		q = q->next;
	q->next = p;
	p->next = NULL;
}

void 
removeDup()
{
	tLNode *current,*runner,*runnerPre;
	current = head->next;
	while(current->next!=NULL)
	{
		runnerPre=current;
		runner = current->next;
		while(runner!=NULL)	
		{
			if( current->data==runner->data )  
			{
				tLNode *t;
				t = runner;
				runnerPre->next = runner->next;
				runner = runner->next;
				delete t;
				continue;
			}
			runnerPre=runner;
			runner=runner->next;
		}
		current=current->next;
	}
}

void 
display()
{
	tLNode *q;
	q = head;
	
	while(q->next!=NULL)
	{
		q = q->next;
		cout<<q->data<<" ";
	}
	cout<<endl;
}

int 
main()
{
	int a[]={3,2,1,3,9,8,6,5,4,9,8,7,10,2,1,5,6,4};
	int len=sizeof(a)/sizeof(a[0]);
	createList(a,len);
	display();
	removeDup();
	display();
	return 0;
}

